package com.diver.flinkdemo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.diver.flinkdemo.entity.xxt.PersonTerminalInfo;
import com.diver.flinkdemo.mapper.mysqlMapper.ClockSettingsMapper;
import com.diver.flinkdemo.mapper.mysqlMapper.PersonTerminalInfoMapper;
import com.diver.flinkdemo.service.IPersonTerminalInfoService;
import com.diver.flinkdemo.utils.DynamicDataSourceUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;
import org.jvnet.hk2.annotations.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Description:
 * @Author: zhangB
 * @Date: 2023/4/14 16:16
 */
@Slf4j
public class IPersonTerminalInfoServiceImpl extends ServiceImpl<PersonTerminalInfoMapper, PersonTerminalInfo> implements IPersonTerminalInfoService {

    private PersonTerminalInfoMapper mapper;
    private SqlSession session = null;
    @Override
    public String getBindPersonId(String cardNum) {
        try {
            session = DynamicDataSourceUtil.mysqlSessionFactory.openSession();
            mapper = session.getMapper(PersonTerminalInfoMapper.class);
            return mapper.getBindPersonId(cardNum);
        } finally {
            endOfSession(session);
        }
    }

    public void endOfSession(SqlSession session) {
        //关闭sqlSession
        if (session != null) {
            log.info("session commit -> session close");
//            session.commit();
            session.close();
        }
    }
}
